package test0927;

import test0927.Person;

public class Driver extends Person{
    private Car car;

    public Driver() {
    }

    public Driver(String name,String sex,int age){
        super(name, sex, age);
    }

    public Driver(String name,String sex,int age,Car car){
        super(name, sex, age);
        this.car=car;

    }


    public Driver(Driver driver){
        super(driver);
        this.car=driver.car;
        //this.car=new Car(driver.car);

    }

    public Car getCar() {
        return car;
    }

    public void setCar(Car car) {
        this.car = car;
    }

    public boolean equals(Object o){
        if (this==o){
            return true;
        }
        if (o instanceof Driver){//确保强制类型转换中超类引用变量引用的是子类对象
            Driver driver=(Driver) o;//超类的引用变量赋予子类引用变量是必须使用强制类型转换
            if (super.equals(driver)&&
                    this.car.equals(driver.getCar())){
                return true;
            }
        }
        return false;
    }

    @Override
    public String toString() {
        return "Driver{" +super.toString()+
                "car=" + car +
                '}';
    }
}
